/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package SysAguas.modelo;

import java.io.Serializable;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author Heitor
 */
@Entity()
@Table(name="reserva")
public class Reserva implements Serializable {

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name="idReserva")
    private Integer id;

    @Column(name="porcentagemDesconto")
    private Integer desconto;

    @Temporal(TemporalType.TIMESTAMP)
    private Date dataChegada;
    @Temporal(TemporalType.TIMESTAMP)
    private Date dataSaida;
    @Temporal(TemporalType.TIMESTAMP)
    private Date dataModificacao;

    @OneToMany(mappedBy="reservaQ",cascade=CascadeType.MERGE)
    private List<Quarto> quartos = new LinkedList<Quarto>();

    @Enumerated(EnumType.STRING)
    private StatusReserva statusReserva;

    @OneToOne(mappedBy = "reservaP",cascade=CascadeType.MERGE)
    private Pagamento pagamentoR;

    @ManyToOne(cascade=CascadeType.MERGE)
    @JoinColumn(name="Hospede_id")
    private Hospede hospedeR;

    @ManyToOne(cascade=CascadeType.MERGE)
    @JoinColumn(name="Pousada_id")
    private Pousada pousadaR;

    public Reserva() {
    }

    public Hospede getHospedeR() {
        return hospedeR;
    }

    public void setHospedeR(Hospede hospedeR) {
        this.hospedeR = hospedeR;
    }
    
    public Pagamento getPagamentoR() {
        return pagamentoR;
    }

    public void setPagamentoR(Pagamento pagamentoR) {
        this.pagamentoR = pagamentoR;
    }

    public Pousada getPousadaR() {
        return pousadaR;
    }

    public void setPousadaR(Pousada pousadaR) {
        this.pousadaR = pousadaR;
    }

    public void removeQuarto(Quarto... quarto){
        for (int i = 0; i < quarto.length; i++) {
            this.quartos.remove(quarto[i]);

        }

    }
        public void removePousada(Pousada p){
        if(pousadaR.equals(p)){
            pousadaR = null;

        }
        }


    public Date getDataModificacao() {
        return dataModificacao;
    }

    public void setDataModificacao(Date dataModificacao) {
        this.dataModificacao = dataModificacao;
    }

    public Date getDataChegada() {
        return dataChegada;
    }

    public void setDataChegada(Date dataChegada) {
        this.dataChegada = dataChegada;
    }

    public Date getDataSaida() {
        return dataSaida;
    }

    public void setDataSaida(Date dataSaida) {
        this.dataSaida = dataSaida;
    }

    public Integer getDesconto() {
        return desconto;
    }

    public void setDesconto(Integer desconto) {
        this.desconto = desconto;
    }

    public void setQuarto (Quarto a ){
        this.quartos.add(a);
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public List<Quarto> getQuartos() {
        return quartos;
    }

    public void setQuartos(List<Quarto> quarto) {
        this.quartos = quarto;
    }

    public StatusReserva getStatusReserva() {
        return statusReserva;
    }

    public void setStatusReserva(StatusReserva statusReserva) {
        this.statusReserva = statusReserva;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Reserva other = (Reserva) obj;
        if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 97 * hash + (this.id != null ? this.id.hashCode() : 0);
        return hash;
    }
}
